
*set globals
		global Year Year2002 Year2003 Year2004 Year2005 Year2006 Year2007 Year2008 Year2009 Year2010 Year2011 Year2012 Year2013 Year2014 Year2015 Year2016
		 
		global Tr tr_minus5 tr_minus4 tr_minus3 tr_minus2 tr_minus1 Tr0 Tr1 Tr2 Tr3 Tr4 Tr5 

		global Field  SOCIALSCIENCES EARTHSCIENCES     BIO_LIFE_CHEM MATH_PHYSICS COMPSCI_ENGI

		global UniversityID i.UniversityID

		 
		global Controls YearsPostDoc AssistantProfessor AssociateProfessor  Male  hindexlag ExternalFunding_mil NSFFundingPrev5Years_mil  CurrentUniversityQuartile   FacultySumNSFBefore_millions 
		global Y NSFFunding_mil

*focals are defined as follows: 
*focal 6 = joined a rotator department but did not overlap with rotator because they changed university (control group 1)
*focal 7 = joined a rotator department but did not overlap with rotator because the rotator changed university (control group 1)
*focal 0 = same advisor but worked in a department without a returning rotator (control group 2)
*focal 3 = different department in a university with a rotator (control group 3)
*focal 1 = joined department the year the rotator left for the NSF or afterwards (treatment group)
*focal 4 = joined department before the rotator left for the NSF (treatment group)
*focal 8 = left a few years after the rotator returned (treatment group)


		
*--------------------------------
*--------------------------------
*TABLE 5
*--------------------------------
*--------------------------------


* MODEL 1: Treatment group (focal 1, focal 4,focal8) and first control group (focal 6, focal7) 
reg  $Y $Tr   $Controls $Field $Year    if  focal1 == 1| focal4 == 1| focal8  == 1 | focal6 == 1|focal7 == 1  , vce(cluster DepartmentID)	


*MODEL 2: Treatment group (focal 1, focal 4,focal8) and second control group (focal 0) 
reg  $Y  $Tr   $Controls $Field $Year    if  focal1 == 1 | focal4 == 1 |focal8 == 1     | focal0 == 1  , vce(cluster DepartmentID)


* MODEL 3: Treatment group (focal 1, focal 4,focal8) and third control group (focal 3) 
reg  $Y $Tr   $Controls $Field $Year    if  focal1 == 1| focal4 == 1| focal8  == 1 | focal3 == 1  , vce(cluster DepartmentID)	


*--------------------------------------
*--------------------------------------
*TABLE 6
*--------------------------------------
*--------------------------------------

*Grant larger than $50,000 
logit  y50k $Tr $Controls $Field $Year     if  focal1 == 1| focal4 == 1| focal8  == 1 | focal6 == 1|focal7 == 1  , vce(cluster DepartmentID)
mfx compute

*Grant larger than $250,000 
logit  y250k $Tr $Controls $Field $Year     if  focal1 == 1| focal4 == 1| focal8  == 1 | focal6 == 1|focal7 == 1  , vce(cluster DepartmentID)
mfx compute

*Grant larger than $500,000 
logit  y500k $Tr $Controls $Field $Year     if  focal1 == 1| focal4 == 1| focal8  == 1 | focal6 == 1|focal7 == 1  , vce(cluster DepartmentID)
mfx compute

*Grant larger than $1,000,000 
logit  y1000k $Tr $Controls $Field $Year     if  focal1 == 1| focal4 == 1| focal8  == 1 | focal6 == 1|focal7 == 1  , vce(cluster DepartmentID)
mfx compute


*--------------------------------------
*--------------------------------------
*TABLE 7
*--------------------------------------
*--------------------------------------

*Test 1 Omit hires who joined the department after the rotator returned
reg  $Y $Tr   $Controls $Field $Year    if  focal1 == 1 & AfterRotator == 0| focal4 == 1 & AfterRotator == 0| focal8  == 1  & AfterRotator == 0   | focal6 == 1 & AfterRotator == 0|focal7 == 1 & AfterRotator == 0  , vce(cluster DepartmentID)	

*Test 2 Add academics with the same advisor who graduated 3 to 10 years before the focal academic who joined a department with a rotator
reg  $Y $Tr   $Controls $Field $Year    if  focal1 == 1| focal4 == 1| focal8 == 1   |  focal5 == 1 | focal0 == 1      , vce(cluster DepartmentID)	

*Test 3 Use Coarsened Exact Matching to populate the control group
reg  $Y $Tr   $Controls $Field $Year    if  focal5 == 0 & cem_matched == 1      [aweight=cem_weights]

